"""
check if login or not
"""
import portalclient
nt=portalclient.PortalClient()
@auth.requires_login()
def management():
   # 
    sysImage= nt.images.list()
    #synchronize with DB
    if sysImage:
        for item in sysImage:
            rows= db(db.images.id==item.id).select()
            if rows:
            #print 'update lai thong tin'
                for row in rows:
                    if row.image_name !=item.name:
                        if item.status== 'ACTIVE':
                            db(db.images.id==item.id).update(image_name=item.name,image_created_time=item.created, is_delete='F')
                        else:
                            db(db.images.id==item.id).update(image_name=item.name,image_created_time=item.created, is_delete='T')     
            else:
                if item.status == 'ACTIVE':
                    db.images.insert(id=item.id,image_name=item.name,image_created_time=item.created,is_delete='F')
    sysImage = db(db.images).select(orderby=db.images.id)
    return locals()

    #return dict()
def create():
    form=crud.create(db.images)
    return locals()